package com.springboot.quanxian.controller.sys;
import com.springboot.quanxian.entity.SysRole;
import com.springboot.quanxian.entity.req.SysRoleReq;
import com.springboot.quanxian.entity.search.SysRoleSearch;
import com.springboot.quanxian.entity.view.SysRoleView;
import com.springboot.quanxian.qpage.QPage;
import com.springboot.quanxian.service.ISysRoleService;
import com.springboot.quanxian.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author lbk
 * @since 2023-04-17
 */
@Validated
@RestController
@RequestMapping("/api/admin/sys-role")
public class SysRoleController {

    @Autowired
    private ISysRoleService service;

    /**
     * 列表分页
     * @param obj
     * @return
     */
    @GetMapping("/getPageList")
    public ResultView getPageList(QPage qPage, SysRoleSearch obj) {
        return this.service.getPageList(qPage,obj);
    }


    /**
     * 下拉不分页列表
     * @return
     */
    @GetMapping("/getSelectList")
    public ResultView getSelectList() {
        List<SysRole> list=this.service.getSelectList();
        return ResultView.ok(list);
    }


    /**
     * 根据ID获取当前数据
     * @return
     */
    @GetMapping("/getById")
    public ResultView getById(@NotNull(message = "ID不能为空") String roleId) {
        SysRoleView dto=this.service.getByIds(roleId);
        return ResultView.ok(dto);
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @PostMapping("/add")
    public ResultView add(SysRoleReq obj) {
        return this.service.add(obj);
    }

    /**
     * 删除
     * @return
     */
    @PostMapping("/del")
    public ResultView del(@NotNull(message = "ID不能为空") String roleId) {
        return this.service.del(roleId);
    }

    /**
     * 批量删除
     * @return
     */
    @PostMapping("/batchDel")
    public ResultView batchDel(SysRoleReq obj) {
        return this.service.batchDel(obj);
    }

    /**
     * 修改
     * @param obj
     * @return
     */
    @PostMapping("/up")
    public ResultView update(SysRoleReq obj) {
        return this.service.up(obj);
    }

    /**
     * 角色菜单列表
     * @return
     */
    @GetMapping("/roleMenuList")
    public ResultView roleMenuList(String roleId) {
        return this.service.roleMenuList(roleId);
    }




}
